﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcAtletIS.Models;

namespace MvcAtletIS.Areas.Admin.Controllers
{
    [Authorize(Roles = "Administrators")]
    public class DisciplinesGroupsController : Controller
    {
        private atletisEntities db = new atletisEntities();

        //
        // GET: /DisciplinesGroups/

        public ViewResult Index(string searchstring)
        {
            var disciplinesGroups = db.DisciplinesGroups.ToList();
            if (!string.IsNullOrEmpty(searchstring))
            {
                disciplinesGroups = disciplinesGroups.Where(dg => dg.Name.Contains(searchstring)).ToList();
            }
            return View(disciplinesGroups);
        }

        //
        // GET: /DisciplinesGroups/Details/5

        public ViewResult Details(string id)
        {
            DisciplinesGroups disciplinesgroups = db.DisciplinesGroups.Single(d => d.ID == id);
            return View(disciplinesgroups);
        }

        //
        // GET: /DisciplinesGroups/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /DisciplinesGroups/Create

        [HttpPost]
        public ActionResult Create(DisciplinesGroups disciplinesgroups)
        {
            disciplinesgroups.Modified = DateTime.Now;
            disciplinesgroups.Sync = true;
            
            if (ModelState.IsValid)
            {
                db.DisciplinesGroups.AddObject(disciplinesgroups);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(disciplinesgroups);
        }
        
        //
        // GET: /DisciplinesGroups/Edit/5
 
        public ActionResult Edit(string id)
        {
            DisciplinesGroups disciplinesgroups = db.DisciplinesGroups.Single(d => d.ID == id);
            return View(disciplinesgroups);
        }

        //
        // POST: /DisciplinesGroups/Edit/5

        [HttpPost]
        public ActionResult Edit(DisciplinesGroups disciplinesgroups)
        {
            disciplinesgroups.Modified = DateTime.Now;
            disciplinesgroups.Sync = true;
            
            if (ModelState.IsValid)
            {
                db.DisciplinesGroups.Attach(disciplinesgroups);
                db.ObjectStateManager.ChangeObjectState(disciplinesgroups, EntityState.Modified);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(disciplinesgroups);
        }

        //
        // GET: /DisciplinesGroups/Delete/5
 
        public ActionResult Delete(string id)
        {
            DisciplinesGroups disciplinesgroups = db.DisciplinesGroups.Single(d => d.ID == id);
            return View(disciplinesgroups);
        }

        //
        // POST: /DisciplinesGroups/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(string id)
        {            
            DisciplinesGroups disciplinesgroups = db.DisciplinesGroups.Single(d => d.ID == id);
            db.DisciplinesGroups.DeleteObject(disciplinesgroups);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}